package com.canyou.model;

import com.canyou.common.CanYouModel;
import com.canyou.controller.EmployeeController;
import com.canyou.util.PageHelper;
import com.jfinal.log.Logger;
import com.jfinal.plugin.activerecord.ActiveRecordException;
import com.jfinal.plugin.activerecord.Page;

/**
 * 员工
 * <p>
 * [Id] ,[Name] ,[PhotoUrl] ,[Sex] ,[Birthday] ,[IdCard] ,[Mobile] ,[Email]
 * ,[Province] ,[City] ,[District] ,[Address] ,[Institution] ,[GraduationTime]
 * ,[Major] ,[Education] ,[ReportTime] ,[SkillRank] ,[Position]
 * 
 * @created cgz 2012-12-15
 */
public class Employee extends CanYouModel<Employee> {

	private static final long serialVersionUID = 5772288520884554849L;

	private static Logger logger = Logger.getLogger(EmployeeController.class);

	public static final Employee dao = new Employee();

	/**
	 * 分页搜索
	 * 
	 * @author cgz 2012-12-17
	 * @param index
	 *            页码
	 * @param skillRank
	 *            技能等级
	 * @param employeeName
	 *            员工姓名
	 * @return
	 */
	public Page<Employee> search(int index, int skillRank, String employeeName) {
		String skill = "";
		if (skillRank != -1) {
			skill = "and SkillRank = " + skillRank;
		}

		String sqlExceptSelect = "from Business_Employee_tb where Name like '%"
				+ employeeName + "%' " + skill + " order by CreatedOn desc ";

		Page<Employee> page = null;
		try {
			page = paginate(index, PageHelper.DEFAULT_PAGE_SIZE, "select *",
					sqlExceptSelect);
		} catch (ActiveRecordException e) {
			logger.fatal(e.getMessage(), e);
		}
		return page;
	}
}
